<?php
	//添加参数内容
	require '../biz/backend.php';

	class action extends backend
	{
		var $get_privilege_id = 86;
		var $post_privilege_id = 86;

		function do_get()
		{
			$template = load( 'template', array( 'domain'=>'tpl.admin' ) );

			//内容模型1新闻2相片3视频4音乐5 FLASH 6软件7商品
			$argument = load( 'biz.argument' );
			$module_type = $argument->content_module_cname;
			$pagesize = $argument->value( 'pagesize' );

			$pid = isset( $this->input['pid'] ) ? $this->input['pid'] : '';
			$data = array ();
			if ( $pid !='' )
			{
				$cate = load( 'biz.cate' );
				$data = $cate->get( array( 'id'=>$pid ) );
			}
			$template->assign( 'data', $data );
			$template->assign( 'module_type', $module_type );
			$template->assign( 'pagesize', $pagesize );
			$template->assign( 'reference', isset( $this->input['reference'] ) ? urldecode( $this->input['reference'] ) : config( 'server.HTTP_REFERER' ) );
			echo $template->parse( 'add_column.php' );
		}

		function do_post()
		{
			$url = isset( $this->input['reference'] ) ? $this->input['reference'] : config( 'domain.admin' ) . 'list_column.php';
			unset( $this->input['reference'] );
			unset( $this->input['superset'] );

			if( preg_match( '!^\w+$!', $this->input['ename'] ) )
			{
				$database = load( 'database' );
				$cate = load( 'biz.cate' );

				$sql = "select id from cate where ename='" . $this->input['ename'] . "' and parent_id=" . $this->input['parent_id'];
				$data = $database->select( $sql );
				if( isset( $data[0] ) )
				{
					$this->prompt( '该栏目已存在', array( array( 'url' => config( 'server.HTTP_REFERER' ), 'name' => '返回' ), array( 'url' => 'list_column.php', 'name' => '返回栏目列表' ) ) );
					exit;
				}
			}
			else
			{
				$this->prompt( '栏目英文名称只能为英文字母', array( array( 'url' => config( 'server.HTTP_REFERER' ), 'name' => '返回' ), array( 'url' => 'list_column.php', 'name' => '返回栏目列表' ) ) );
				exit;
			}

			// 非顶级栏目不能设置二级域名
			if( $this->input['parent_id'] !=0 && ( $this->input['dev_domain'] != '' || $this->input['product_domain'] != '' ) )
			{
				$this->input['dev_domain'] = '';
				$this->input['product_domain'] = '';
			}

			//栏目信息入库
			$result = $cate->add( $this->input );

			if ( $result['success'] )
			{
				$this->prompt( '成功添加栏目', array( array( 'url' => config( 'domain.admin' ) . 'add_column.php?reference=' . urlencode( $url ), 'name' => '继续添加栏目' ), array( 'url' => 'list_column.php', 'name' => '返回栏目列表' ) ) );
			}
			else
			{
				$this->prompt( '添加栏目失败', $this->transform( $result['message'], config( 'server.HTTP_REFERER' ) ), 10 );
			}
		}
	}

	$action = new action();
	$action->run();
?>